require.config({
  baseUrl: '../../',
  paths: {
    jquery: 'plugins/jQuery/jquery-2.2.3.min',
    flavr: 'plugins/flavr/flavr.min',
    select2: 'plugins/select2/select2.min',
    public: 'public/js/public.min'
  },
  shim: {
    flavr: {
      deps: ['jquery']
    },
    select2: {
      deps: ['jquery']
    }
  }
});
require(['jquery', 'flavr', 'select2', 'public'], function ($) {
  $(function(){
    var obj = {
      init: function () {
        this.load();
      },
      load: function () {
        var _this = this;
        $('#header').load('../head.html', function () {
          _this.year = $('.header-select-year').on('change', function () {
            _this.setTitle();
            _this.queryData();
          });
          _this.month = $('.header-select-month').on('change', function () {
            _this.setTitle();
            _this.queryData();
          });

          _this.setTitle();
          _this.queryData();
        });
        $('#navigator').load('../left-nav.html');
      },
      setTitle: function () {
        var year = this.year.find('option:selected').text();
        var month = this.month.find('option:selected').text();
        $('.title').html(year + '年' + month + '月' + GetQueryString('name') + '全科医生');
      },
      queryData: function () {
        publicAjax(basePath + 'general', 'post', {
          typeId: GetQueryString('typeId'),
          year: this.year.val(),
          month: this.month.val()
        }, function (data) {
          console.log(data);
          if (data.ret === 1) {
            var list = data.data || [];
            var num1 = 0;
            var num2 = 0;
            var num3 = 0;
            var num4 = 0;
            var num5 = 0;
            var num6 = 0;
              str = '';
            if (list.length) {
              var year = '今';
              for (var i = 0; i < list.length; i++) {
                num1 += list[i].longtermGoal;
                num2 += list[i].longtermRate;
                num3 += list[i].currentGoal;
                num4 += list[i].currentRate;
                num5 += list[i].actual;
                num6 += list[i].actualRate;
                str += (
                  '<tr>' +
                  '<td>' + fixStr(list[i].hospitalName) + '</td>' +
                  '<td class="text-right">' + fixLine(list[i].longtermGoal) + '</td>' +
                  '<td class="text-right">' + fixLine2(list[i].longtermRate) + '</td>' +
                  '<td class="text-right">' + fixLine(list[i].currentGoal) + '</td>' +
                  '<td class="text-right">' + fixLine2(list[i].currentRate) + '</td>' +
                  '<td class="text-right">' + fixLine(list[i].actual) + '</td>' +
                  '<td class="text-right">' + fixLine2(list[i].actualRate) + '</td>' +
                  '</tr>'
                );
                year = list[i].year || year;
              }

              $('.table-year').html(year);
            } else {
              str = '<tr><td colspan="10" class="text-center">暂无数据!</td></tr>';
            }
            $('#table-data').find('tbody').html(str);
            $('#table-data tfoot').find('.QKYSQWS').text(fixLine2(num1));
            $('#table-data tfoot').find('.QWQRKQKYSS').text(fixLine2(num2));
            $('#table-data tfoot').find('.JNQKYSQWS').text(fixLine2(num3));
            $('#table-data tfoot').find('.JNQRKQKYSS').text(fixLine2(num4));
            $('#table-data tfoot').find('.QKYSS').text(fixLine2(num5));
            $('#table-data tfoot').find('.QRKQKYSS').text(fixLine2(num6));
          } else {
            flavrShowByTime(data.msg, null, 'error', false);
          }
        });
      }
    };

    obj.init();
  });
});